package com.five.monkey.vo;

import com.five.monkey.util.TimeUtils;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author 狻猊
 * @date 2021/8/9 下午12:05
 */
@Data
@Accessors(chain = true)
public class CommonVo<T> implements Serializable {

    private int code;

    private String desc;

    private String dateTime;

    private T data;

    private CommonVo() {
        this(200, "SUCCESS");
    }

    public CommonVo(int code, String desc) {
        this(code, desc, null);
    }

    private CommonVo(int code, String desc, T data) {
        this.code = code;
        this.desc = desc;
        this.data = data;
        this.dateTime = TimeUtils.parseDate();
    }

    public static <T> CommonVo<T> ok(T data) {
        return Objects.isNull(data) ? new CommonVo<T>() : new CommonVo<T>(200, "SUCCESS", data);
    }

    public static <T> CommonVo<T> exception(int code, String desc) {
        return new CommonVo<>(code, desc);
    }
}
